import sys
sys.path.append("../main/")
from MainTable import MainTable
import unittest
import os

class TestMainTable(unittest.TestCase):

    def setUp(self):
        self.main = MainTable("../../databases/tests/main.db")

    def testInsertUser(self):
        self.main.insertUser("u346156")
        self.main.createDashboard("GES", "u346156")
        self.main.createTable("test", "u346156")
        self.main.createTable("new", "u346156")
        self.main.createGroup("users", "u346156")
        self.main.addTableToGroup("users", "test", "u346156")
        self.main.addTableToGroup("users", "new", "u346156")
        dash = self.main.getDashboards("u346156")
        #print dash
        self.assertTrue(["GES"] == dash)
        tables = self.main.getTables("u346156")
        #print tables
        self.assertTrue(["test","new"] == tables)
        self.main.createOperation("u346156", "Just Testing", "../operations/test.py")
        self.main.addOperationToGroup("users", "Just Testing", "u346156")
        operations = self.main.getOperations("u346156")
        print operations
        self.assertTrue(operations == [["Just Testing", "../operations/test.py"]])
        self.main.createWidget("Pie", 1, "test", "GES", [["min", "500"],["max", "30000"]], ["displayName"], "u346156")
        widget = self.main.getWidget("GES", "u346156", 1)
        print widget
        user = self.main.checkUser("u346156")
        print user
        self.assertTrue(user)
        user = self.main.checkUser("test")
        print user
        self.assertFalse(user)

    def tearDown(self):
        self.main.close()
        os.remove("../../databases/tests/main.db")
        
        
if __name__ == '__main__':
    unittest.main()
